package com.gnerv.battle.boot.framework.controller;

import com.gnerv.battle.boot.framework.business.ManageAccountBusiness;
import com.gnerv.battle.boot.framework.common.model.RestResult;
import com.gnerv.battle.boot.framework.model.dto.ManageAccountCreateDTO;
import com.gnerv.battle.boot.framework.model.dto.ManageAccountDTO;
import com.gnerv.battle.boot.framework.model.dto.ManageAccountUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/manage/account")
public class ManageAccountController {

    private final ManageAccountBusiness manageAccountBusiness;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody ManageAccountCreateDTO manageAccountCreateDTO) {
        return manageAccountBusiness.create(manageAccountCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return manageAccountBusiness.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody ManageAccountUpdateDTO manageAccountUpdateDTO) {
        return manageAccountBusiness.updateByUkId(manageAccountUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<ManageAccountDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return manageAccountBusiness.selectByUkId(ukId);
    }

    @GetMapping(value = "list")
    public RestResult<List<ManageAccountDTO>> listByUsername(@RequestParam(required = false, value = "username") String username,
                                                             @RequestParam(required = false, value = "page") Integer page,
                                                             @RequestParam(required = false, value = "size") Integer size) {
        return manageAccountBusiness.listByUsername(username, page, size);
    }

}
